package com.hzdaba.aiapi.utils;

import org.jasypt.util.password.PasswordEncryptor;
import org.jasypt.util.password.StrongPasswordEncryptor;

/**
 * 密码工具类
 *
 * @author 刘逸晖
 */
public class PasswordUtils {

    /**
     * 密码加密器
     */
    private static PasswordEncryptor passwordEncryptor = new StrongPasswordEncryptor();

    /**
     * 加密密码
     *
     * @param plainPassword 预加密的密码
     * @return 加密后的密码
     */
    public static String encryptPassword(String plainPassword) {
        return PasswordUtils.passwordEncryptor.encryptPassword(plainPassword);
    }

    /**
     * 检查加密前的密码和加密后的密码是否一致
     *
     * @param plainPassword     加密前的密码
     * @param encryptedPassword 加密后的密码
     * @return 是否一致
     */
    public static boolean checkPassword(String plainPassword, String encryptedPassword) {
        return PasswordUtils.passwordEncryptor.checkPassword(plainPassword, encryptedPassword);
    }

}
